<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<!--采购计划修改-->
<div class="modal fade" id="modal-update">
    <div class="modal-dialog" style="width:1200px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">采购计划修改</h4>
            </div>
            <div class="modal-body">
                <form id="updateForm" class="form-horizontal">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="trackNumber" class="col-sm-4 control-label">物料跟踪号</label>
                                <div class="col-sm-8">
                                    <input id="trackNumber" type="text" class="form-control" name="trackNumber"
                                           readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="materialDesc" class="col-sm-4 control-label">物料描述</label>
                                <div class="col-sm-8">
                                    <input id="materialDesc" type="text" class="form-control" name="materialDesc"
                                           readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="proCode" class="col-sm-4 control-label">采购项目号</label>
                                <div class="col-sm-8">
                                    <input id="proCode" type="text" class="form-control" name="proCode" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="proName" class="col-sm-4 control-label">采购项目名</label>
                                <div class="col-sm-8">
                                    <input id="proName" type="text" class="form-control" name="proName" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="num" class="col-sm-4 control-label">预购数量</label>
                                <div class="col-sm-8">
                                    <input id="num" type="text" class="form-control" name="num" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="unit" class="col-sm-4 control-label">预购单位</label>
                                <div class="col-sm-8">
                                    <input id="unit" type="text" class="form-control" name="unit" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="pcNo" class="col-sm-4 control-label">采购合同</label>
                                <div class="col-sm-8">
                                    <input id="pcNo" type="text" class="form-control" name="pcNo" maxlength="255"
                                           autocomplete="off"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="purchNum" class="col-sm-4 control-label">采购数量</label>
                                <div class="col-sm-8">
                                    <input id="purchNum" type="number" class="form-control" name="purchNum"
                                           min="0" step="0.01"  autocomplete="off" readonly />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="purchUnit" class="col-sm-4 control-label">采购单位</label>
                                <div class="col-sm-8">
                                    <input id="purchUnit" type="text" class="form-control" name="purchUnit"
                                           maxlength="255" autocomplete="off"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="taxRate" class="col-sm-4 control-label">税率</label>
                                <div class="col-sm-8">
                                    <input id="taxRate" type="text" class="form-control" name="taxRate" maxlength="255"
                                           autocomplete="off"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="billType" class="col-sm-4 control-label">票据类型</label>
                                <div class="col-sm-8">
                                    <select class="form-control select2" id="billType" name="billType"
                                            style="width: 100%;">


                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="unitPrice" class="col-sm-4 control-label">含税单价</label>
                                <div class="col-sm-8">
                                    <input id="unitPrice" type="number" class="form-control" name="unitPrice"
                                           min="0" step="0.01"  autocomplete="off"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="totalPrice" class="col-sm-4 control-label">总价</label>
                                <div class="col-sm-8">
                                    <input id="totalPrice" type="number" class="form-control" name="totalPrice"
                                           min="0" step="0.01"  autocomplete="off"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="supplier" class="col-sm-4 control-label">供应商</label>
                                <div class="col-sm-8">
                                    <input id="supplier" type="text" class="form-control" name="supplier"
                                           maxlength="255" autocomplete="off"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="purchCreate" class="col-sm-4 control-label">采购日期</label>
                                <div class="col-sm-8">
                                    <input id="purchCreate" type="text" class="form-control datepicker"
                                           name="purchCreate">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="exportRecord" class="col-sm-4 control-label">导出记录</label>
                                <div class="col-sm-8">
                                    <input id="exportRecord" type="text" class="form-control"
                                           name="exportRecord" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="applicant" class="col-sm-4 control-label">申请人</label>
                                <div class="col-sm-8">
                                    <input id="applicant" type="text" class="form-control" name="applicant"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="purchaser" class="col-sm-4 control-label">业务员</label>
                                <div class="col-sm-8">
                                    <input id="purchaser" type="text" class="form-control" name="purchaser"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="preOrderRemark" class="col-sm-4 control-label">预购备注</label>
                                <div class="col-sm-8">
                                    <input id="preOrderRemark" type="text" class="form-control"
                                           name="preOrderRemark" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="purchRemark" class="col-sm-4 control-label">采购备注</label>
                                <div class="col-sm-8">
                                    <input id="purchRemark" type="text" class="form-control datepicker"
                                           name="purchRemark" autocomplete="off" maxlength="255"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="createTime" class="col-sm-4 control-label">预购日期</label>
                                <div class="col-sm-8">
                                    <input id="createTime" type="text" class="form-control datepicker" name="createTime"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="code" class="col-sm-4 control-label">关联预购编码</label>
                                <div class="col-sm-8">
                                    <input id="code" type="text" class="form-control" name="code" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">关联预购主题</label>
                                <div class="col-sm-10">
                                    <input id="name" type="text" class="form-control" name="name" readonly>
                                </div>
                            </div>
                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--采购计划收货数量修改-->
<div class="modal fade" id="modal-updateReceivedNum">
    <div class="modal-dialog" style="width:1200px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">采购计划修改</h4>
            </div>
            <div class="modal-body">
                <form id="updateReceivedNumForm" class="form-horizontal">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormTrackNumber" class="col-sm-4 control-label">物料跟踪号</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormTrackNumber" type="text" class="form-control" name="trackNumber"
                                           readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormMaterialDesc" class="col-sm-4 control-label">物料描述</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormMaterialDesc" type="text" class="form-control" name="materialDesc"
                                           readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormProCode" class="col-sm-4 control-label">采购项目号</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormProCode" type="text" class="form-control" name="proCode" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormProName" class="col-sm-4 control-label">采购项目名</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormProName" type="text" class="form-control" name="proName" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormNum" class="col-sm-4 control-label">预购数量</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormNum" type="text" class="form-control" name="num" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormUnit" class="col-sm-4 control-label">预购单位</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormUnit" type="text" class="form-control" name="unit" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPcNo" class="col-sm-4 control-label">采购合同</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPcNo" type="text" class="form-control" name="pcNo" maxlength="255"
                                           autocomplete="off" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPurchNum" class="col-sm-4 control-label">采购数量</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPurchNum" type="text" class="form-control" name="purchNum"
                                           maxlength="255" autocomplete="off" readonly />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPurchUnit" class="col-sm-4 control-label">采购单位</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPurchUnit" type="text" class="form-control" name="purchUnit"
                                           maxlength="255" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormTaxRate" class="col-sm-4 control-label">税率</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormTaxRate" type="text" class="form-control" name="taxRate" maxlength="255"
                                            readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormBillType" class="col-sm-4 control-label">票据类型</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormBillType" type="text" class="form-control" name="billType"
                                           maxlength="255" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormUnitPrice" class="col-sm-4 control-label">含税单价</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormUnitPrice" type="number" class="form-control" name="unitPrice"
                                           min="0" step="0.01"  readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormTotalPrice" class="col-sm-4 control-label">总价</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormTotalPrice" type="number"  min="0" step="0.01"  class="form-control" name="totalPrice"
                                           readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormSupplier" class="col-sm-4 control-label">供应商</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormSupplier" type="text" class="form-control" name="supplier"
                                           maxlength="255" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPurchCreate" class="col-sm-4 control-label">采购日期</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPurchCreate" type="text" class="form-control datepicker"
                                           name="purchCreate" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormExportRecord" class="col-sm-4 control-label">导出记录</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormExportRecord" type="text" class="form-control"
                                           name="exportRecord" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormApplicant" class="col-sm-4 control-label">申请人</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormApplicant" type="text" class="form-control" name="applicant"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPurchaser" class="col-sm-4 control-label">业务员</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPurchaser" type="text" class="form-control" name="purchaser"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPreOrderRemark" class="col-sm-4 control-label">预购备注</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPreOrderRemark" type="text" class="form-control"
                                           name="preOrderRemark" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormPurchRemark" class="col-sm-4 control-label">采购备注</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormPurchRemark" type="text" class="form-control datepicker"
                                           name="purchRemark" readonly/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormCreateTime" class="col-sm-4 control-label">预购日期</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormCreateTime" type="text" class="form-control datepicker" name="createTime"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormCode" class="col-sm-4 control-label">关联预购编码</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormCode" type="text" class="form-control" name="code" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormName" class="col-sm-4 control-label">关联预购主题</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormName" type="text" class="form-control" name="name" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="updateReceivedNumFormReceivedNum" class="col-sm-4 control-label">收货数量</label>
                                <div class="col-sm-8">
                                    <input id="updateReceivedNumFormReceivedNum" type="number" class="form-control" name="receivedNum"
                                           autocomplete="off" min="0" step="0.01"  />
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-update_received_num">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--导入-->
<div class="modal fade" id="modal-import">
    <div class="modal-dialog" style="width:100%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">导入采购计划</h4>
            </div>
            <div class="modal-body" style="padding: 5px!important;">
                <section class="content" style="padding: 0px!important;">
                    <div class="row" style="margin-bottom: 24px">
                        <button type="button" class="btn btn-default pull-right" data-dismiss="modal">取消</button>
                        <a id="btn-import-purchase-plan" shiro:hasPermission="buy:procurementplan:edit"
                           href="javascript:void(0);"
                           class="btn btn-info pull-right" style="margin-right: 10px">
                            <span class="Bold">确定</span>
                        </a>
                        <a shiro:hasPermission="buy:procurementplan:edit" href="javascript:void(0);"
                           class="btn btn-success pull-right" style="margin-right: 10px"
                           onclick="js.modal.open('modal-import-plan')">
                            <span class="Bold">导入</span>
                        </a>
                    </div>
                    <div class="row">
                        <form id="importPurchasePlanForm" class="form-horizontal">
                            <div class="col-xs-12"
                                 style="max-width: 100%;max-height: 80vh;overflow: auto;padding: 0!important;">
                                <table id="table_import" class="t1 t3">
                                    <thead>
                                    <tr>
                                        <td colspan="17" style="font-size: 16px;letter-spacing: 4px;">
                                            采购计划单
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td style="width: 40px;">序号</td>
                                        <td style="width: 140px;">物料跟踪号</td>
                                        <td style="width: 80px;">物料描述</td>
                                        <td style="width: 80px;">采购项目号</td>
                                        <td style="width: 80px;">采购项目名</td>
                                        <td style="width: 80px;">预购数量</td>
                                        <td style="width: 80px;">预购单位</td>
                                        <td style="width: 100px;">采购合同</td>
                                        <td style="width: 80px;">采购数量</td>
                                        <td style="width: 40px;">采购单位</td>
                                        <td style="width: 60px;">税率</td>
                                        <td style="width: 240px;">票据类型</td>
                                        <td style="width: 80px;">含税单价</td>
                                        <td style="width: 80px;">总价</td>
                                        <td>供应商</td>
                                        <td style="width: 60px;">采购备注</td>
                                        <td></td>
                                    </tr>
                                    </thead>
                                    <tbody id="out">
                                    <tr>
                                        <td>1</td>
                                        <td>
                                            <input type="text" class="form-control" name="trackNumber" readonly/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="materialDesc" readonly/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="proCode" readonly/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="proName" readonly/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="num" readonly/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="unit" readonly>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="pcNo" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="purchNum" autocomplete="off"
                                                   maxlength="255" readonly>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="purchUnit" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="taxRate" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="billType" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="unitPrice" autocomplete="off"
                                                   min="0" step="0.01">
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="totalPrice" autocomplete="off"
                                                   min="0" step="0.01">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="supplier" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="purchRemark"
                                                   autocomplete="off" maxlength="255">
                                        </td>
                                        <td>

                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </form>
                    </div>
                    <!--                    <div th:include="include :: tip"></div>-->
                </section>
            </div>
        </div>
    </div>
</div>
<!--详情-->
<div class="modal fade" id="modal-info">
    <div class="modal-dialog" style="width:100%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看预购计划</h4>
            </div>
            <div class="modal-body">
                <section class="content" style="padding: 5px!important;">
                    <div class="row">
                        <form id="infoPreOrderPlanForm" class="form-horizontal">
                            <div class="col-xs-12"
                                 style="max-width: 100%;max-height: 80vh;overflow: auto;padding: 0!important;">
                                <table id="table_import_info" class="t1 t3">
                                    <thead>
                                    <!--                                    <tr>-->
                                    <!--                                        <td colspan="12">-->
                                    <!--                                            <img th:src="@{/img/logo.png}" width="64px" height="40px"-->
                                    <!--                                                 style="margin-top: -30px">-->
                                    <!--                                            <div style="display: inline-block;margin-top: 5px;margin-left: 20px">-->
                                    <!--                                                <span style="letter-spacing: 24px;display: block;line-height: 20px">&nbsp;辽宁忠旺机械设备制造有限公司</span>-->
                                    <!--                                                <span style="display: block;font-size: 12px;line-height: 20px">Liaoning Zhongwang Machinery Equipment Manufacturing Co., Ltd</span>-->
                                    <!--                                            </div>-->
                                    <!--                                        </td>-->
                                    <!--                                        <td style="width: 8%"></td>-->
                                    <!--                                    </tr>-->
                                    <tr>
                                        <td colspan="12" style="font-size: 16px;letter-spacing: 4px;">
                                            预购计划单
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" style="width: 8%">主题</td>
                                        <td colspan="7" style="width: 11%;font-size: 14px;">
                                            <input type="text" class="form-control" name="name"
                                                   placeholder="请输入预购主题"/>
                                        </td>
                                        <td style="width: 8%">预购编号</td>
                                        <td colspan="2" style="width: 21%">
                                            <input style="background: #FFFFFF" type="text" class="form-control"
                                                   name="code" readonly="readonly"/>
                                        </td>

                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td style="width: 3%">序号</td>
                                        <td colspan="3">物料描述</td>
                                        <td style="width: 8%">预购项目号</td>
                                        <td style="width: 12%">预购项目名</td>
                                        <td style="width: 6%">业务员</td>
                                        <td style="width: 6%">预购数量</td>
                                        <td style="width: 4%">预购单位</td>
                                        <td style="width: 6%">品牌</td>
                                        <td style="width: 8%">型号/标准号</td>
                                        <td style="width: 10%">预购备注</td>
                                        <td></td>
                                    </tr>
                                    </thead>
                                    <tbody id="outForInfo">
                                    <tr>
                                        <td>1</td>
                                        <td colspan="3">
                                            <input type="text" class="form-control" name="materialDesc1"
                                                   autocomplete="off" maxlength="255"/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="proCode" autocomplete="off"
                                                   maxlength="255"/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="proName" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="purchaser" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="num" autocomplete="off"  min="0" step="0.01" >
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="unit1" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="brand" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="model" autocomplete="off"
                                                   maxlength="255">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="preOrderRemark"
                                                   autocomplete="off" maxlength="255">
                                        </td>
                                        <td>
                                            <label class="badge label-default" name="uploadFileText">无附件</label>
                                            <input type="hidden" class="form-control" name="id" readonly="readonly"/>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </form>
                    </div>
                    <!--                    <div th:include="include :: tip"></div>-->
                </section>
            </div>
        </div>
    </div>
</div>
<!--导入模态框导入Excel-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-import-plan">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Excel信息导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input id="import-file" class="btn" type="file" name="file">
                        <p class="help-block">请按导出模板格式进行导入，信息与模板信息对应。</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btn-import" type="button" class="btn btn-success">
                    <span class="Bold">确定</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header"><h1>采购计划编辑</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="form-group">
                        <label for="input_details"><input id="input_details" value="2" type="radio"
                                                          name="dataDisplayMode" checked="checked"/>&nbsp;明细</label>
                        <label for="input_summary"><input id="input_summary" value="1" type="radio"
                                                          name="dataDisplayMode"/>&nbsp;汇总</label>
                    </div>
                    <!--汇总-->
                    <form id="queryFormForSummary" method="post" class="form-horizontal" style="display: none;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="width:320px">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">预购主题</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="name"
                                               class="form-control"
                                               placeholder="请输入预购主题">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">预购编号</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="code"
                                               class="form-control"
                                               placeholder="请输入预购编号">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">申请人</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="applicant"
                                               class="form-control"
                                               placeholder="请输入申请人">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">业务员</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="purchaser"
                                               class="form-control"
                                               placeholder="请输入业务员">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">收货状态</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <select name="receiptStatus"
                                                class="form-control"
                                                style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                            <option value="" selected="selected">全部</option>
                                            <option value="1">未收货</option>
                                            <option value="2">部分收货</option>
                                            <option value="3">无需收货</option>
                                            <option value="4">收货完成</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group" style="width: 640px;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">预购日期</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input type="text" class="form-control datepicker" name="createTimeStartTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="createTimeEndTime"
                                               readonly="readonly"/>
                                    </div>
                                </div>
                                <button id="btn-summary-search" type="button" class="btn btn-success pull-right" onclick="search()">
                                    <span class="Bold"><i class="fa fa-search"></i> 搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                    <!--高级-->
                    <form id="queryFormForAdvanced" action="exportExcelForAdvanced" method="post"
                          class="form-horizontal" style="display: none;">
                        <input type="hidden" name="selectedTrackNumber"/>
                        <div class="form-inline">
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">物料跟踪号</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="trackNumber"
                                           class="form-control"
                                           placeholder="请输入物料跟踪号">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">物料描述</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="materialDesc"
                                           class="form-control"
                                           placeholder="请输入物料描述">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">采购项目号</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="proCode"
                                           class="form-control"
                                           placeholder="请输入采购项目号">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">采购项目名</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="proName"
                                           class="form-control"
                                           placeholder="请输入采购项目名">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">预购单位</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="unit"
                                           class="form-control"
                                           placeholder="请输入预购单位">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">采购合同</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="pcNo"
                                           class="form-control"
                                           placeholder="请输入采购合同">
                                </div>
                            </div>
                            <div class="form-group" style="width:640px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">预购数量</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input type="text"
                                           style="width: 102px;"
                                           class="form-control"
                                           name="minNum"
                                           placeholder="请输入下限"/>
                                    <span> 至 </span>
                                    <input type="text"
                                           style="width: 102px;"
                                           class="form-control"
                                           name="maxNum"
                                           placeholder="请输入上限"/>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">采购单位</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="purchUnit"
                                           class="form-control"
                                           placeholder="请输入采购单位">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">税率</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="taxRate"
                                           class="form-control"
                                           placeholder="请输入税率">
                                </div>
                            </div>
                            <div class="form-group" style="width:640px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">采购数量</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <input type="text"
                                           style="width: 102px"
                                           class="form-control"
                                           name="minPurchNum"
                                           placeholder="请输入下限"/>
                                    <span> 至 </span>
                                    <input type="text"
                                           style="width: 102px"
                                           class="form-control"
                                           name="maxPurchNum"
                                           placeholder="请输入上限"/>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">供应商</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="supplier"
                                           class="form-control"
                                           placeholder="请输入供应商">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">导出记录</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="exportRecord"
                                           class="form-control"
                                           placeholder="请输入导出记录">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">物料编码</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="materialCode"
                                           class="form-control"
                                           placeholder="请输入物料编码">
                                </div>
                            </div>
                            <div class="form-group" style="width:640px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">含税单价</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <input type="text"
                                           style="width: 102px"
                                           class="form-control"
                                           name="minUnitPrice"
                                           placeholder="请输入下限"/>
                                    <span> 至 </span>
                                    <input type="text"
                                           style="width: 102px"
                                           class="form-control"
                                           name="maxUnitPrice"
                                           placeholder="请输入上限"/>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">申请人</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="applicant"
                                           class="form-control"
                                           placeholder="请输入申请人">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">业务员</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="purchaser"
                                           class="form-control"
                                           placeholder="请输入业务员">
                                </div>
                            </div>
                            <div class="form-group" style="width:640px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">总价</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <input type="text"
                                           style="width: 102px"
                                           class="form-control"
                                           name="minTotalPrice"
                                           placeholder="请输入下限"/>
                                    <span> 至 </span>
                                    <input type="text"
                                           style="width: 102px"
                                           class="form-control"
                                           name="maxTotalPrice"
                                           placeholder="请输入上限"/>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">预购备注</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="preOrderRemark"
                                           class="form-control"
                                           placeholder="请输入预购备注">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">采购备注</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="purchRemark"
                                           class="form-control"
                                           placeholder="请输入采购备注">
                                </div>
                            </div>
                            <div class="form-group" style="width:640px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">预购日期</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <input type="text"
                                           style="padding: 4px!important;"
                                           class="form-control datepicker"
                                           name="createTimeStartTime"
                                           readonly="readonly"/>
                                    <span> 至 </span>
                                    <input type="text"
                                           style="padding: 4px!important;"
                                           class="form-control datepicker"
                                           name="createTimeEndTime"
                                           readonly="readonly"/>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">关联预购主题</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="name"
                                           class="form-control"
                                           placeholder="请输入关联预购主题">
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label" style="width: 120px;">预购计划编码</label>
                                <div class="col-md-7" style="padding: 0;">
                                    <input style="width: 100%"
                                           type="text"
                                           name="code"
                                           class="form-control"
                                           placeholder="请输入预购计划编码">
                                </div>
                            </div>
                            <div class="form-group" style="width:640px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">采购日期</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <input type="text"
                                           style="padding: 4px!important;"
                                           class="form-control datepicker"
                                           name="purchCreateStartTime"
                                           readonly="readonly"/>
                                    <span> 至 </span>
                                    <input type="text"
                                           style="padding: 4px!important;"
                                           class="form-control datepicker"
                                           name="purchCreateEndTime"
                                           readonly="readonly"/>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">票据类型</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <select name="billType"
                                            class="form-control select2"
                                            style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                        <option selected value=""> ---请选择---</option>
                                        <option th:each="dict : ${dictCommonList}" th:value="${dict.name}"
                                                th:text="${dict.name}"></option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">收货状态</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <select name="receiptStatus"
                                            class="form-control"
                                            style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">未收货</option>
                                        <option value="2">已收货</option>
                                        <option value="3">无需收货</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">采购状态</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <select name="isProcurement"
                                            class="form-control"
                                            style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1">未采购</option>
                                        <option value="2">已采购</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" style="width:320px">
                                <label class="col-md-4 control-label"
                                       style="width: 120px;">是否有附件</label>
                                <div class="col-md-7"
                                     style="padding: 0;">
                                    <select name="attachmentIsExist"
                                            class="form-control"
                                            style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                        <option value="0" selected="selected">全部</option>
                                        <option value="1">有附件</option>
                                        <option value="2">没有附件</option>
                                        >
                                    </select>
                                </div>
                            </div>
                            <button type="button" class="btn btn-default pull-right" style="margin-left: 20px"
                                    onclick="switchGeneralSearch('general')">
                                <span class="Bold"><i class="fa fa-search-minus"></i> 普通搜索</span>
                            </button>
                            <button id="btn-advanced-search" type="button" class="btn btn-success pull-right" onclick="search()">
                                <span class="Bold"><i class="fa fa-search"></i> 搜索</span>
                            </button>
                        </div>
                    </form>
                    <!--常规-->
                    <form id="queryFormForGeneral" action="exportExcel" method="post" class="form-horizontal">
                        <div class="row">
                            <input type="hidden" name="selectedTrackNumber"/>
                            <div class="form-inline">
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label" style="width: 120px;">物料描述</label>
                                    <div class="col-md-7" style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="materialDesc"
                                               class="form-control"
                                               placeholder="请输入物料描述">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">物料跟踪号</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="trackNumber"
                                               class="form-control"
                                               placeholder="请输入物料跟踪号">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">采购项目号</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="proCode"
                                               class="form-control"
                                               placeholder="请输入采购项目号">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">采购项目名</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="proName"
                                               class="form-control"
                                               placeholder="请输入采购项目名">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">供应商</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="supplier"
                                               class="form-control"
                                               placeholder="请输入供应商">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">采购合同</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="pcNo"
                                               class="form-control"
                                               placeholder="请输入采购合同">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label" style="width: 120px;">物料编码</label>
                                    <div class="col-md-7" style="padding: 0;">
                                        <input style="width: 100%"
                                               type="text"
                                               name="materialCode"
                                               class="form-control"
                                               placeholder="请输入物料编码">
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">收货状态</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <select name="receiptStatus"
                                                class="form-control"
                                                style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                            <option value="">全部</option>
                                            <option value="1" selected="selected">未收货</option>
                                            <option value="2">已收货</option>
                                            <option value="4">部分收货</option>
                                            <option value="3">无需收货</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group" style="width: 320px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">采购状态</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <select name="isProcurement"
                                                class="form-control"
                                                style="text-align: center!important;text-align-last: center!important;width:100%!important;">
                                            <option value="">请选择</option>
                                            <option value="1" selected="selected">未采购</option>
                                            <option value="2">已采购</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group" style="width: 640px!important;">
                                    <label class="col-md-4 control-label"
                                           style="width: 120px;">采购日期</label>
                                    <div class="col-md-7"
                                         style="padding: 0;">
                                        <input type="text" class="form-control datepicker"
                                               name="purchCreateStartTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker"
                                               name="purchCreateEndTime"
                                               readonly="readonly"/>
                                    </div>
                                </div>
                                <button type="button" class="btn btn-default pull-right" style="margin-left: 20px;"
                                        onclick="switchAdvancedSearch('advance')">
                                    <span class="Bold"><i class="fa fa-search-plus"></i> 高级搜索</span>
                                </button>
                                <button id="btn-general-search" type="button" class="btn btn-success pull-right" onclick="search()">
                                    <span class="Bold"><i class="fa fa-search"></i> 搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                    <div class="row" id="toolbar">
                        <div id="div_toolbar" class="form-inline">
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" style="width: 2800px;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    /**
     * detailsTable 明细表
     */
    let detailsTable;
    /**
     * summaryTable 汇总表
     */
    let summaryTable;
    let receiptStatusState = ['', "未收货", "部分收货", "无需收货", "收货完成"];
    let receiptStatusColors = ['', "label-info", "label-warning", "label-primary", "label-success"];
    let statusState = ['已删除', "未提交", "已提交", "被驳回", "已撤消", "待指派", "已指派"];
    let statusColors = ['label-danger', "label-default", "label-primary", "label-warning", "label-danger", "label-success", "label-primary"];
    /**
     * 当前表模式
     * @type {string}
     */
    let tableMode = 'details';

    /**
     * 加载明细模式的搜索内容，并在queryFormForGeneral的action上添加导出Excel的URL
     */
    function loadAdvancedQueryForm() {
        $("#queryFormForSummary").hide();
        $("#queryFormForGeneral").hide();
        $("#queryFormForAdvanced").show();
    }

    /**
     * 加载明细模式的搜索内容，并在queryFormForGeneral的action上添加导出Excel的URL
     */
    function loadDetailsQueryForm() {
        $("#queryFormForSummary").hide();
        $("#queryFormForAdvanced").hide();
        $("#queryFormForGeneral").show();
    }

    /**
     * 加载汇总模式的搜索内容，并删除对应的导出Excle的URL
     */
    function loadSummaryQueryForm() {
        $("#queryFormForGeneral").hide();
        $("#queryFormForAdvanced").hide();
        $("#queryFormForSummary").show();
    }

    /**
     * 加载汇总表数据
     */
    function loadSummary() {
        if (detailsTable !== undefined) {
            js.table.destroy(detailsTable);
        }
        /** 汇总 */
        summaryTable = js.table.init({
            url: ctx + "buy/procurementPlan/summaryList",
            paginationVAlign: 'both',
            pageSize: 15,
            pageList: [10, 15, 25, 50, 100, 300, 1000],               // 可供选择的每页的行数
            showColumns: true,
            showExport: false,
            showRefresh: true,
            clickToSelect: true,
            uniqueId: "code",
            queryForm: "queryFormForSummary",
            onLoadSuccess: function () {
                $("#btn-summary-search").prop('disabled', false).removeClass('disabled');
            },
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        if (row.procurementStatus === 1) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {
                    title: "预购主题", field: 'name',
                    formatter: function (value, row, index, field) {
                        if (value && value.length > 50) {
                            return '<span title="' + value + '">' + value.substring(0, 50) + '</span> ';
                        } else {
                            return value;
                        }
                    }
                },
                {
                    title: "预购编号", field: 'code', width: '170px'
                },
                {
                    title: "预购日期", field: 'createTime', width: '150px'
                },
                {
                    title: "审批状态", field: 'status', width: '100px',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + statusColors[value] + '">' + statusState[value] + '</span> ';
                        }
                    }
                },
                {
                    title: "收货状态",
                    field: 'receiptStatus',
                    width: '100px',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + receiptStatusColors[value] + '">' + receiptStatusState[value] + '</span> ';
                        }
                    }
                },
                {title: "申请人", field: 'applicant', width: '100px'},
                {title: "业务员", field: 'purchaser', width: '160px'},
                {title: "驳回原因", field: 'rejectReason', width: '100px'},
                {
                    title: "操作",
                    width: '240px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('buy:procurementplan:view')) {
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openInfoModal(\'' + row.code + '\')"> 详情</a> ');
                        }
                        if (row.procurementStatus === 1) {
                            if (hasP('buy:procurementplan:edit')) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="rejectPlan(\'' + row.code + '\')"> 驳回</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });
    }

    /**
     * 加载明细表数据
     */
    function loadDetails(formId, url) {
        if (summaryTable !== undefined) {
            js.table.destroy(summaryTable);
        }
        if (detailsTable !== undefined) {
            js.table.destroy(detailsTable);
        }
        /** 明细 */
        detailsTable = js.table.init({
            url: ctx + url,
            paginationVAlign: 'both',
            pageSize: 15,
            pageList: [10, 15, 25, 50, 100, 300, 1000],               // 可供选择的每页的行数
            showColumns: true,
            showExport: false,
            showRefresh: true,
            clickToSelect: true,
            uniqueId: "code",
            queryForm: formId,
            onLoadSuccess: function () {
                $("#btn-advanced-search").prop('disabled', false).removeClass('disabled');
                $("#btn-general-search").prop('disabled', false).removeClass('disabled');
            },
            columns: [
                {
                    checkbox: true,
                    width: 30
                },
                {
                    title: '序号', width: 50,
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {
                    title: "物料跟踪号", field: 'trackNumber'
                },
                {
                    title: "物料描述", field: 'materialDesc', width: 400
                },
                {
                    title: "物料编码", field: 'materialCode'
                },
                {
                    title: "采购项目号", field: 'proCode'
                },
                {
                    title: "采购项目名", field: 'proName'
                },
                {
                    title: "预购数量", field: 'num'
                },
                {
                    title: "预购单位", field: 'unit'
                },
                {
                    title: "采购合同", field: 'pcNo'
                },
                {
                    title: "采购数量", field: 'purchNum'
                },
                {
                    title: "采购单位", field: 'purchUnit'
                },
                {
                    title: "税率", field: 'taxRate'
                },
                {
                    title: "票据类型", field: 'billType'
                },
                {
                    title: "含税单价", field: 'unitPrice'
                },
                {
                    title: "总价", field: 'totalPrice'
                },
                {title: "供应商", field: 'supplier'},

                {
                    title: "采购日期", field: 'purchCreate'
                },
                {
                    title: "导出记录", field: 'exportRecord'
                },
                {
                    title: "申请人", field: 'applicant'
                },
                {title: "业务员", field: 'purchaser'},
                {title: "预购备注", field: 'preOrderRemark'},
                {title: "采购备注", field: 'purchRemark'},
                {
                    title: "预购日期", field: 'createTime', width: '150px'
                },
                {
                    title: "关联预购主题", field: 'name', width: '150px'
                },
                {
                    title: "采购状态",
                    field: 'pcNo',
                    width: '150px',
                    formatter: function (value, row, index) {
                        if (value === undefined || value === null || value === '') {
                            return '<label class="badge label-default">未采购</label>';
                        } else {
                            return '<label class="badge label-success">已采购</label>';
                        }
                    }
                },
                {
                    title: "附件", field: 'attachmentName', formatter: function (value, row, index) {
                        if(row.attachmentName !== undefined && row.attachmentName !== ""){
                            return '<a href="javascript:void(0)" onclick="downloadFile(' + row.id + ',\'' + row.formatter + '\')" title="点击下载">' + row.attachmentName + '</a>';
                        }
                        return '--';
                    }
                },
                {
                    title: "收货状态",
                    field: 'receiptStatus',
                    width: '150px',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<label class="badge label-default">未收货</label>';
                        } else if (value === 2) {
                            return '<label class="badge label-success">已收货</label>';
                        } else if (value === 3) {
                            return '<label class="badge label-primary">无需收货</label>';
                        } else if (value === 4) {
                            return '<label class="badge label-warning">部分收货</label>';
                        }
                    }
                },
                {
                    title: "收货数量",
                    field: 'receivedNum',
                    width: '150px'
                },
                {
                    title: "收货进度",
                    field: '',
                    width: '150px',
                    formatter: progressFormatter
                },
                {
                    title: "操作",
                    width: '240px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('buy:procurementplan:edit')) {
                            if (row.pcNo !== null && row.pcNo !== '') {
                                if (row.receiptStatus !== 3) {
                                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="noNeedReceiveGoods(\'' + row.trackNumber + '\')"> 无需收货</a> ');
                                }
                                if(row.receiptStatus !== 3){
                                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openUpdateReceivedNumModal(\'' + row.trackNumber + '\')"> 收货</a> ');
                                }
                                actions.push('<a class="btn btn-pinterest btn-xs" href="javascript:void(0)" onclick="revocationProcurement(\'' + row.trackNumber + '\')"> 撤销采购</a> ');
                            }
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openUpdateModal(\'' + row.trackNumber + '\')"> 修改</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
    }
    /* 3. 单元格 formatter */
    function progressFormatter(value,row,index){
        let p = 0;
        if(row.purchNum === undefined || row.purchNum === 0){
            p = 0;
        }else{
            let val = ((row.receivedNum/row.purchNum) * 100).toFixed(2);
            p = Number(val)||0;          // 容错
        }
        const color = percent2color(p);
        const html=`
    <div style="
        position:relative;
        width:100%; height:22px;
        background:#e9ecef; border-radius:4px;border:#333 solid 1px; ">
      <div style="
          position:absolute; left:0; top:0; bottom:0;
          width:${p}%;
          background:${color};
          border-radius:4px;
          transition:width .3s;"></div>
      <span style="
          position:relative; z-index:2;
          display:block; text-align:center; line-height:22px;
          color:#000; text-shadow:0 0 2px #FFF;
          font-size:12px;">${p}%</span>
    </div>`;
        return html;
    }
    /* 2. 颜色计算器：把 0-100 映射到渐变起止颜色 */
    function percent2color(p){
        const stops = [
            {pos:0,   r:255,g:67 ,b:54},
            {pos:25,  r:255,g:152,b:0},
            {pos:50,  r:255,g:235,b:59},
            {pos:75,  r:129,g:199,b:132},
            {pos:100, r:76 ,g:175,b:80}
        ];
        // 1. 越界保护
        p = Math.max(0, Math.min(100, p));

        // 2. 找到第一个 >= p 的区间
        let i = stops.findIndex(s => p <= s.pos);

        // 3. 边界保护：i=0 时左端还是 0，i=4 时右端还是 100
        const i1 = Math.max(0, i - 1);
        const i2 = Math.min(stops.length - 1, i);
        const s1 = stops[i1];
        const s2 = stops[i2];

        const t = (p - s1.pos) / (s2.pos - s1.pos);
        const r = Math.round(s1.r + (s2.r - s1.r) * t);
        const g = Math.round(s1.g + (s2.g - s1.g) * t);
        const b = Math.round(s1.b + (s2.b - s1.b) * t);
        return `rgb(${r},${g},${b})`;
    }
    /**
     * 切换到常规搜索
     */
    function switchGeneralSearch(mode) {
        let url = "";
        if (mode === 'general') {
            url = "buy/procurementPlan/list"
        } else if (mode === 'advance') {
            url = "buy/procurementPlan/advanceList"
        }
        loadDetailsQueryForm();
        loadDetails('queryFormForGeneral', url);
        tableMode = 'details';
        loadToolBar();
    }

    /**
     * 切换到高级搜索
     */
    function switchAdvancedSearch(mode) {
        let url = "";
        if (mode === 'general') {
            url = "buy/procurementPlan/list"
        } else if (mode === 'advance') {
            url = "buy/procurementPlan/advanceList"
        }
        loadAdvancedQueryForm();
        loadDetails('queryFormForAdvanced', url);
        tableMode = 'details';
        loadToolBar();


    }

    /**
     * 导入Excel
     */
    function importExcel() {
        $("#out").empty();
        js.modal.open("modal-import");
    }

    /**
     * 导出Excel
     */
    function exportExcel() {
        let selectedRows = detailsTable.bootstrapTable('getSelections');
        const selectedTrackNumber = selectedRows.map(row => {
            return '\''+row.trackNumber+'\'';
        });
        const queryFormForGeneralIsVisible = $('#queryFormForGeneral').is(':visible');
        if (queryFormForGeneralIsVisible) {
            if(selectedTrackNumber !== null && selectedTrackNumber.length > 0){
                $("#queryFormForGeneral input[name='selectedTrackNumber']").val(selectedTrackNumber.join(','));
            }
            $("#queryFormForGeneral").submit();
            setInterval(() => {$("#queryFormForGeneral input[name='selectedTrackNumber']").val(null);},1000);
        }
        const queryFormForAdvancedIsVisible = $('#queryFormForAdvanced').is(':visible');
        if (queryFormForAdvancedIsVisible) {
            if(selectedTrackNumber !== null && selectedTrackNumber.length > 0){
                $("#queryFormForAdvanced input[name='selectedTrackNumber']").val(selectedTrackNumber.join(','));
            }
            $("#queryFormForAdvanced").submit();
            setInterval(() => {$("#queryFormForAdvanced input[name='selectedTrackNumber']").val(null);},1000);
        }
        js.modal.alert("导出Excel完毕，注意：红色背景列头为必填项！白色背景列头对应的整列内容不可改动！");
    }

    /**
     * 下载附件
     * @param id 附件所属数据行ID
     * @param fileNameTitle 文件名
     */
    function downloadFile(id, fileNameTitle) {
        if (hasP('buy:procurementplan:download')) {
            if (fileNameTitle !== undefined && fileNameTitle !== null) {
                js.post({
                    url: ctx + "buy/procurementPlan/getAttachmentIsExist",
                    data: {id: id},
                    success: function (result) {
                        //如果文件存在
                        if (result.msg == "有文件") {
                            //下载文件
                            location.href = ctx + "buy/procurementPlan/downloadAttachment/" + id;
                        } else {
                            js.modal.warning("没有附件可以下载！");
                        }
                    }
                });
            }
        } else {
            js.modal.warning("你没有下载权限！");
        }
    }

    /**
     * 打开详情模态框
     * @param code
     */
    function openInfoModal(code) {
        js.post({
            url: ctx + "buy/procurementPlan/getProOrderPlanListByCode",
            data: {code: code},
            success: function (result) {
                let list = result.data;
                $('#infoPreOrderPlanForm input[name="name"]').val(list[0].name);
                $('#infoPreOrderPlanForm input[name="code"]').val(list[0].code);
                $("#outForInfo").empty();
                for (let i = 0; i < list.length; i++) {
                    let fileClass = 'label-default';
                    let fileStatus = '无附件';
                    let fileNameTitle = '';
                    if (list[i].attachmentName !== undefined && list[i].attachmentName !== null && list[i].attachmentName !== '') {
                        fileClass = 'label-success';
                        fileStatus = '有附件';
                        fileNameTitle = 'title = ' + list[i].attachmentName + '（点击下载）';
                    }
                    let no = i + 1;
                    $("#outForInfo").append(`<tr>
                                        <td>${no}</td>
                                        <td colspan="3">
                                            <input type="text" class="form-control" name="materialDesc" autocomplete="off" maxlength="255" value="${list[i].materialDesc}" readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="proCode" autocomplete="off" maxlength="255" value="${list[i].proCode}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="proName" autocomplete="off" maxlength="255" value="${list[i].proName}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td >
                                            <input type="text" class="form-control" name="purchaser" autocomplete="off" maxlength="255" value="${list[i].purchaser}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="num" autocomplete="off"  min="0" step="0.01"  value="${list[i].num}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="unit" autocomplete="off" maxlength="255" value="${list[i].unit}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="brand" autocomplete="off" maxlength="255" value="${list[i].brand}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="model" autocomplete="off" maxlength="255" value="${list[i].model}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="preOrderRemark" autocomplete="off" maxlength="255" value="${list[i].preOrderRemark}"  readonly="readonly" style="background: #FFFFFF" />
                                        </td>
                                        <td>
                                            <label onclick="downloadFile(${list[i].id},\'${fileNameTitle}\')" class="badge ${fileClass}" name="uploadFileText" ${fileNameTitle}>${fileStatus}</label>
                                            <input type="hidden" class="form-control" name="id" readonly="readonly" value="${list[i].id}" />
                                        </td>
                                    </tr>`);
                }
                js.modal.open("modal-info");
            }
        })

    }

    /**
     * 汇总模式 驳回单条
     * @param code
     */
    function rejectPlan(code) {
        js.modal.prompt("请编辑驳回原因", function (reason) {
            if (reason == null) {
                return;
            }
            doReject([code], reason);
        });
    }

    /**
     * 汇总模式 批量驳回
     * @param code
     */
    function rejectAll() {
        js.modal.prompt("请编辑驳回原因", function (reason) {
            if(reason !== null){
                let selectedRows = summaryTable.bootstrapTable('getSelections');
                const selectedCodes = selectedRows.map(row => {
                    return row.code;
                });
                if(selectedRows.length > 0){
                    doReject(selectedCodes, reason);
                }
            }
        });
    }

    /**
     * 执行驳回
     * @param codes 被驳回的预购单编号数组
     * @param reason 驳回原因
     */
    function doReject(codes, reason) {
        js.post({
            url: ctx + "buy/procurementPlan/reject",
            data: {
                codes: codes,
                rejectReason: reason
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.hide("modal-info");
                    js.table.search(summaryTable);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /**
     * 加载工具栏
     */
    function loadToolBar() {
        if (tableMode === 'summary') {
            if (hasP('buy:procurementplan:edit')) {
                $("#div_toolbar").html(`<a href="javascript:void(0);"
                               class="btn btn-danger pull-right" style="margin-right: 10px" onclick="rejectAll()">
                                <span class="Bold">批量驳回</span>

                            </a>`);
            }
        } else if (tableMode === 'details') {
            if (hasP('buy:procurementplan:edit')) {
                $("#div_toolbar").html(`
                            <a href="javascript:void(0);"
                               class="btn btn-warning pull-right" style="margin-right: 10px" onclick="noNeedReceiptAll()">
                                <span class="Bold">批量无需收货</span>
                            </a>
                            <a href="javascript:void(0);"
                               class="btn btn-success pull-right" style="margin-right: 10px" onclick="receiptAll()">
                                <span class="Bold">批量收货</span>
                            </a>
                            <a href="javascript:void(0);"
                               class="btn btn-success pull-right" style="margin-right: 10px"
                               onclick="importExcel()">
                                <span class="Bold">导入</span>
                            </a>
                            <a id="button_export"
                               href="javascript:void(0);"
                               class="btn btn-primary pull-right"
                               style="margin-right: 10px"
                               onclick="exportExcel()">
                                <span class="Bold">导出</span>
                            </a>`);
            }
        }
    }

    /**
     * 时间类型格式化成字符串
     * @param date
     * @returns {*|string}
     */
    // 格式化函数
    function fmtLocalDate(date) {
        if (!(date instanceof Date)) return date;
        // 转成 yyyy-mm-dd 本地时间
        const y = date.getFullYear();
        const m = String(date.getMonth() + 1).padStart(2, '0');
        const d = String(date.getDate() + 1).padStart(2, '0');
        return `${y}-${m}-${d}`;
    }

    /** 计算表格序号 */
    function computerNo() {
        $("#table_import tbody tr").each(function (i, e) {
            let rowNum = eval(i + 1);
            $(this).children("td:first").text(rowNum);
        });
    }

    /**
     * 批量无需收货
     */
    function noNeedReceiptAll() {
        let selectedRows = detailsTable.bootstrapTable('getSelections');
        const selectedTrackNumber = selectedRows.map(row => {
            return row.trackNumber;
        });
        if(selectedTrackNumber.length > 0){
            noNeedReceiveGoods(JSON.stringify(selectedTrackNumber));
        }
    }

    /**
     * 批量收货
     */
    function receiptAll() {
        let selectedRows = detailsTable.bootstrapTable('getSelections');
        const selectedTrackNumber = selectedRows.map(row => {
            return row.trackNumber;
        });
        if(selectedTrackNumber.length > 0){
            receiveGoods(JSON.stringify(selectedTrackNumber));
        }
    }

    /**
     * 撤销采购
     * @param trackNumbersJsonStr
     */
    function revocationProcurement(trackNumbersJsonStr){
        let trackNumbers = [];
        if (!trackNumbersJsonStr.includes("[") && !trackNumbersJsonStr.includes("]")) {
            trackNumbers.push(trackNumbersJsonStr);
        } else {
            trackNumbers = JSON.parse(trackNumbersJsonStr);
        }
        let content = '';
        for (const trackNumber of trackNumbers) {
            content+="【"+trackNumber+"】，";
        }
        content = content.substring(0, content.length - 1);
        js.modal.confirm("您确认要对物料跟踪号为" +content + "的采购计划的进行收货码？", function () {
            js.post({
                url: ctx + "buy/procurementPlan/revocationProcurementByTrackNumber",
                data: {
                    trackNumbers: trackNumbers
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success("操作成功！");
                        if (tableMode === 'summary') {
                            js.table.search(summaryTable);
                        } else if (tableMode === 'details') {
                            js.table.search(detailsTable);
                        }
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        });
    }

    /** 收货 */
    function receiveGoods(trackNumbersJsonStr) {
        let trackNumbers = [];
        if (!trackNumbersJsonStr.includes("[") && !trackNumbersJsonStr.includes("]")) {
            trackNumbers.push(trackNumbersJsonStr);
        } else {
            trackNumbers = JSON.parse(trackNumbersJsonStr);
        }
        let content = '';
        for (const trackNumber of trackNumbers) {
            content+="【"+trackNumber+"】，";
        }
        content = content.substring(0, content.length - 1);
        js.post({
            url: ctx + "buy/procurementPlan/getPcNoNullCountByTrackNumber",
            data: {
                trackNumbers: trackNumbers
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    if (result.data > 0) {
                        js.modal.warning("您所选的采购计划中有未填写采购合同的计划，无法进行收货！");
                    } else {
                        js.modal.confirm("批量收货时，所有收货数量将按照采购数量自动写入，您确认要对物料跟踪号为" + content + "的采购计划的进行收货码？", function () {
                            js.post({
                                url: ctx + "buy/procurementPlan/changeReceiptStatusByTrackNumber",
                                data: {
                                    trackNumbers: trackNumbers,
                                    receiptStatus: 2
                                },
                                success: function (result) {
                                    if (result.type === web_status.SUCCESS) {
                                        js.modal.success("操作成功！");
                                        if (tableMode === 'summary') {
                                            js.table.search(summaryTable);
                                        } else if (tableMode === 'details') {
                                            js.table.search(detailsTable);
                                        }
                                    } else {
                                        js.modal.warning(result.msg);
                                    }
                                }
                            })
                        });
                    }
                }
                else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 无需收货 */
    function noNeedReceiveGoods(trackNumbersJsonStr) {
        let trackNumbers = [];
        if (!trackNumbersJsonStr.includes("[") && !trackNumbersJsonStr.includes("]")) {
            trackNumbers.push(trackNumbersJsonStr);
        } else {
            trackNumbers = JSON.parse(trackNumbersJsonStr);
        }
        let content = '';
        for (const trackNumber of trackNumbers) {
            content+="【"+trackNumber+"】，";
        }
        content = content.substring(0, content.length - 1);
        js.post({
            url: ctx + "buy/procurementPlan/getPcNoNullCountByTrackNumber",
            data: {
                trackNumbers: trackNumbers
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    if(result.data > 0) {
                        js.modal.warning("您所选的采购计划中有未填写采购合同的计划，无法进行无需收货！");
                    }else{
                        js.modal.confirm("您确认对物料跟踪号为" +content + "的采购计划无需收货码？", function () {
                            js.post({
                                url: ctx + "buy/procurementPlan/changeReceiptStatusByTrackNumber",
                                data: {
                                    trackNumbers: trackNumbers,
                                    receiptStatus: 3
                                },
                                success: function (result) {
                                    if (result.type === web_status.SUCCESS) {
                                        js.modal.success("操作成功！");
                                        if (tableMode === 'summary') {
                                            js.table.search(summaryTable);
                                        } else if (tableMode === 'details') {
                                            js.table.search(detailsTable);
                                        }
                                    } else {
                                        js.modal.warning(result.msg);
                                    }
                                }
                            })
                        });
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /**
     * 验证输入的内容是否是正数，由于Excel在表格中输入的百分号的内容在JS中会自动的转换成小数，
     * 所以新增此验证。
     * @param v
     * @returns {boolean}
     */
    function isPositiveNumeric(v){
        if(typeof v === 'string' &&
            v.trim() !== '' &&
            !isNaN(v) &&
            isFinite(v) &&
            Number(v) > 0){
            return true;
        }else if(typeof v === 'number'){
            return true;
        }
        return false;
    }
    $(function () {
        /** 导入 */
        $('#btn-import').click(function () {
            let files = $("#import-file")[0].files;
            let fileReader = new FileReader();
            fileReader.onload = function (ev) {
                let workbook;
                let plans;
                try {
                    let data = ev.target.result,
                        workbook = XLSX.read(data, {type: 'binary', cellDates: true, dateNF: 'yyyy-mm-dd'}), // 以二进制流方式读取得到整份excel表格对象
                        plans = []; // 存储获取到的数据
                    // 遍历每张表读取
                    for (let sheet in workbook.Sheets) {
                        if (workbook.Sheets.hasOwnProperty(sheet)) {
                            plans = plans.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
                            break; // 只取第一张表
                        }
                    }
                    if (plans.length === 0) {
                        js.modal.alert("无法读取文件内容");
                    } else {
                        let isBreak = false;
                        let errorInfo = '';
                        $("#out").empty();
                        plans.forEach((value, index) => {
                            let trackNumber = value['物料跟踪号'] === undefined ? '' : value['物料跟踪号'];
                            let materialDesc = value['物料描述'] === undefined ? '' : value['物料描述'];
                            let proCode = value['采购项目号'] === undefined ? '' : value['采购项目号'];
                            let proName = value['采购项目名'] === undefined ? '' : value['采购项目名'];
                            let num = value['预购数量'] === undefined ? '' : value['预购数量'];
                            let unit = value['预购单位'] === undefined ? '' : value['预购单位'];
                            let pcNo = value['采购合同'] === undefined ? '' : value['采购合同'];
                            let purchNum = value['采购数量'] === undefined ? '' : value['采购数量'];
                            let purchUnit = value['采购单位'] === undefined ? '' : value['采购单位'];
                            let taxRate = value['税率'] === undefined ? '' : value['税率'];
                            if(taxRate !== '' && isPositiveNumeric(taxRate)){
                                //将转换成小数的百分数税率乘以100，然后以字符串形式加上百分号实现税率的显示。
                                taxRate = eval(Number(taxRate) * 100) + '%';
                            }else{
                                errorInfo+="第"+eval(index + 1)+"行数据中，税率格式不正确，正确格式例如：13%，请检查导入的Excel文档！\r\n";
                                isBreak = true;

                            }
                            let billType = value['票据类型'] === undefined ? '' : value['票据类型'];
                            let unitPrice = value['含税单价'] === undefined ? '' : value['含税单价'];
                            let totalPrice = value['总价'] === undefined ? '' : value['总价'];
                            let supplier = value['供应商'] === undefined ? '' : value['供应商'];
                            let purchRemark = value['采购备注'] === undefined ? '' : value['采购备注'];
                            $("#out").append(`<tr>
                                        <td>1</td>
                                        <td style="background:rgb(238,238,238)!important;">
                                            <input style="background:rgb(238,238,238)!important;" type="text" class="form-control" name="trackNumber" readonly value="${trackNumber}" />
                                        </td>
                                        <td style="background:rgb(238,238,238)!important;">
                                            ${materialDesc}
                                        </td>
                                        <td style="background:rgb(238,238,238)!important;">
                                            ${proCode}
                                        </td>
                                        <td style="background:rgb(238,238,238)!important;">
                                            ${proName}
                                        </td>
                                        <td style="background:rgb(238,238,238)!important;">
                                            ${num}
                                        </td>
                                        <td style="background:rgb(238,238,238)!important;">
                                           ${unit}
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="pcNo" autocomplete="off" maxlength="255" value="${pcNo}" />
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="purchNum" autocomplete="off"  min="0" step="0.01"  value="${purchNum}" readonly />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="purchUnit" autocomplete="off" maxlength="255" value="${purchUnit}" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="taxRate" autocomplete="off" maxlength="255" value="${taxRate}" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="billType" autocomplete="off" maxlength="255" value="${billType}" />
                                        </td>
                                        <td>
                                            <input type="number"  min="0" step="0.01"  class="form-control" name="unitPrice" autocomplete="off" value="${unitPrice}" />
                                        </td>
                                        <td>
                                            <input type="number" min="0" step="0.01"  class="form-control" name="totalPrice" autocomplete="off" value="${totalPrice}" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="supplier" autocomplete="off" maxlength="255" value="${supplier}" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" name="purchRemark" autocomplete="off" maxlength="255" value="${purchRemark}" />
                                        </td>
                                        <td>
                                        </td>
                                    </tr>`);

                        });
                        if(isBreak){
                            $("#out").empty();
                            js.modal.alert("警告："+errorInfo);
                            return;
                        }else{
                            computerNo();
                        }
                        js.modal.hide("modal-import-plan");
                    }
                } catch (e) {
                    js.modal.alert("无法读取文件或文件类型有错误");
                }
            };
            // 以二进制方式打开文件
            fileReader.readAsBinaryString(files[0]);
        });


        /**
         * 加载工具栏
         */
        loadToolBar();
        /**
         * 如果选择明细模式
         */
        $("#input_details").on("change", function (e) {
            if ($("#input_details").is(":checked")) {
                loadDetailsQueryForm();
                loadDetails('queryFormForGeneral', "buy/procurementPlan/list");
                tableMode = 'details';
                loadToolBar();
            }
        });
        /**
         * 如果选择汇总模式
         */
        $("#input_summary").on("change", function (e) {
            if ($("#input_summary").is(":checked")) {
                loadSummaryQueryForm();
                loadSummary();
                tableMode = 'summary';
                loadToolBar();
            }
        });


        /**
         * 加载明细数据
         */
        loadDetails('queryFormForGeneral', "buy/procurementPlan/list");

        /**
         * 表格多行数据中必填项验证
         * @param tbodyId tbodyId
         * @param nameArray 必填项名称数组
         * return 验证是否通过
         */
        function requiredFieldVerification(tbodyId, nameArray) {
            let isPass = true;
            let tBody = $('#' + tbodyId);
            let trCount = tBody.children('tr').length;
            let passCount = 0;
            if (trCount > 0) {
                let trs = tBody.children("tr");
                let firstPurchaser = $(trs[0]).find("input[name='purchaser']").val();
                for (let i = 0; i < trCount; i++) {
                    for (let j = 0; j < nameArray.length; j++) {
                        let input_element = $(trs[i]).find("input[name='" + nameArray[j] + "']");
                        if (input_element.val() === "") {
                            input_element.css({
                                'border-color': 'red',
                                'border-style': 'solid',
                                'border-width': '1px'
                            });
                            createTipBox(input_element, "必填！", input_element.parent());
                            isPass = false;
                        } else {
                            input_element.css({
                                'border-color': 'transparent',
                                'border-style': 'none',
                                'border-width': '0px'
                            });
                            removeTipBox(input_element);
                        }
                    }
                }
            } else {
                isPass = false;
            }
            return isPass;
        }

        /**
         * 确认导入采购计划
         */
        $("#btn-import-purchase-plan").on('click', function (e) {
            $("#btn-import-purchase-plan").attr("disabled", "disabled");
            let nameArray = ["trackNumber", "pcNo", "purchNum", "purchUnit", "taxRate", "billType", "unitPrice", "totalPrice", "supplier", "purchCreate"];
            if (requiredFieldVerification("out", nameArray)) {
                // 1. 创建 FormData 存储所有数据和文件
                let formData = new FormData();
                // 2. 遍历表格的每一行（tr）
                $('#out tr').each(function (rowIndex) {
                    let $tr = $(this); // 当前行
                    let $td = $tr.find("td");
                    formData.append(`rows[${rowIndex}].trackNumber`, $td[1].children[0].value);
                    formData.append(`rows[${rowIndex}].pcNo`, $td[7].children[0].value);
                    formData.append(`rows[${rowIndex}].purchNum`, $td[8].children[0].value);
                    formData.append(`rows[${rowIndex}].purchUnit`, $td[9].children[0].value);
                    formData.append(`rows[${rowIndex}].taxRate`, $td[10].children[0].value);
                    formData.append(`rows[${rowIndex}].billType`, $td[11].children[0].value);
                    formData.append(`rows[${rowIndex}].unitPrice`, $td[12].children[0].value);
                    formData.append(`rows[${rowIndex}].totalPrice`, $td[13].children[0].value);
                    formData.append(`rows[${rowIndex}].supplier`, $td[14].children[0].value);
                    formData.append(`rows[${rowIndex}].purchRemark`, $td[15].children[0].value);
                });
                //提交所有数据以及要上传的文件
                $.ajax({
                    url: ctx + "buy/procurementPlan/importExcel", // 后端接口地址
                    type: 'POST',
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (response) {
                        if (response.type === 'SUCCESS') {
                            js.modal.success(response.msg);
                            $("#btn-create-report-plan").removeAttr("disabled");
                            js.modal.hide("modal-import");
                            js.table.refresh(detailsTable);
                        } else {
                            js.modal.fail(response.msg);
                            $("#btn-create-report-plan").removeAttr("disabled");
                        }
                    },
                    error: function (xhr, status, error) {
                        $("#btn-create-report-plan").removeAttr("disabled");
                    }
                });
            } else {
                $("#btn-create-report-plan").removeAttr("disabled");
            }
        });
        js.validate.init("updateForm", {
            fields: {
                trackNumber: {validators: {notEmpty: {message: '请输入内容'}}},
                pcNo: {validators: {notEmpty: {message: '请输入合同编号'}}},
                purchNum: {validators: {notEmpty: {message: '请输入采购数量'}}},
                purchUnit: {validators: {notEmpty: {message: '请输入采购单位'}}},
                taxRate: {validators: {notEmpty: {message: '请输入税率'}}},
                billType: {validators: {notEmpty: {message: '请输选择票据类型'}}},
                unitPrice: {validators: {notEmpty: {message: '请输入含税单价'}}},
                totalPrice: {validators: {notEmpty: {message: '请输入总价'}}},
                supplier: {validators: {notEmpty: {message: '请输入供应商'}}},
                purchCreate: {validators: {notEmpty: {message: '请输选择采购日期'}}},
            }
        });
        js.validate.init("updateReceivedNumForm", {
            fields: {
                receivedNum: {validators: {notEmpty: {message: '请输入收货数量'}}},
            }
        });

        /**
         * 保存修改结果
         */
        $("#btn-edit").on("click", function (e) {
            //去掉不可见字符
            $("#updateForm input[name='pcNo']").val(stripInvisibleLegacy($("#updateForm input[name='pcNo']").val()));
            js.validSubmit({
                formId: "updateForm",
                url: ctx + "buy/procurementPlan/saveUpdate",
                data: new FormData($("#updateForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        search();
                        js.modal.hide("modal-update");
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
        /**
         * 保存修改收货数量
         */
        $("#btn-update_received_num").on("click", function (e) {
            let receivedNum =  stripInvisibleLegacy($("#updateReceivedNumForm input[name='receivedNum']").val());
            let updateReceivedNumFormPurchNum =  stripInvisibleLegacy($("#updateReceivedNumFormPurchNum").val());
            if(receivedNum !== undefined &&
                receivedNum !== null &&
                updateReceivedNumFormPurchNum !== undefined &&
                updateReceivedNumFormPurchNum !== null &&
                Number(receivedNum) <= Number(updateReceivedNumFormPurchNum)){
                //去掉不可见字符
                $("#updateReceivedNumForm input[name='receivedNum']").val(stripInvisibleLegacy($("#updateReceivedNumForm input[name='receivedNum']").val()));
                js.validSubmit({
                    formId: "updateReceivedNumForm",
                    url: ctx + "buy/procurementPlan/updateFormReceivedNum",
                    data: new FormData($("#updateReceivedNumForm")[0]),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            search();
                            js.modal.hide("modal-updateReceivedNum");
                        } else {
                            js.modal.warning(result.msg);
                        }
                        js.modal.closeLoading();
                    }
                });
            }else{
                js.modal.warning("收货数量不可大于采购数量！");
            }

        });
    });
    function stripInvisibleLegacy(str) {
        return str
            // 1. 清除所有 Unicode 空白/不可见类别
            .replace(/\p{White_Space}/gu, '')
            // 2. 再手动把零宽空白干掉（它们属于 Cf 类别，但个别浏览器可能漏掉）
            .replace(/[\u200B\u200C\u200D\uFEFF]/g, '');
    }
    /**
     * 创建提示框
     * @param $targetInput 目标Input
     * @param customTipText 提示内容
     * @param $parent 父级td
     */
    function createTipBox($targetInput, customTipText, $parent) {
        $parent.css({
            position: 'relative', // 核心：作为绝对定位的基准
            padding: '5px' // 可选：给父容器留一点内边距，避免提示框贴边
        });
        // 创建提示框容器
        var $tipBox = $('<div class="' + $targetInput.attr("name") + 'custom-tip-box"></div>').css({
            'position': 'absolute', // 改为相对定位
            'top': '0px', // 相对于父容器原始位置向下偏移5px（即input下方）
            'left': '0', // 相对于父容器左侧对齐
            'background': 'red',
            'color': 'white',
            'border-radius': '3px',
            'z-index': '10', // 无需过高，父容器内层级足够
            'display': 'flex',
            'align-items': 'center',
        });

        // 提示文字
        var $tipText = $('<span></span>').text(customTipText);

        // 关闭按钮
        var $closeBtn = $('<span>×</span>').css({
            'cursor': 'pointer',
            'font-weight': 'bold',
            'font-size': '14px',
            'user-select': 'none'
        });

        // 关闭按钮事件
        $closeBtn.on('click', function () {
            $tipBox.remove();
        });

        // 组装提示框
        $tipBox.append($tipText).append($closeBtn);
        $parent.append($tipBox);
    }

    /**
     * 删除提示框
     * @param $targetInput
     */
    function removeTipBox($targetInput) {
        $("." + $targetInput.attr("name") + "custom-tip-box").remove();
    }

    /** 明细汇总表格搜索 */
    function search() {
        if (tableMode === 'summary') {
            $("#btn-summary-search").prop('disabled', true).addClass('disabled');
            js.table.search(summaryTable);
        } else if (tableMode === 'details') {
            $("#btn-advanced-search").prop('disabled', true).addClass('disabled');
            $("#btn-general-search").prop('disabled', true).addClass('disabled');
            js.table.search(detailsTable);
        }
    }
    /**
     * 收货修改
     */
    function openUpdateReceivedNumModal(trackNumber) {
        js.post({
            url: ctx + "buy/procurementPlan/getBPreOrderPlanAllInfoByTrackNumber",
            data: {trackNumber: trackNumber},
            success: function (result) {
                //如果文件存在
                if (result.type === "SUCCESS") {
                    result.data.purchNum = result.data.num;
                    $("#updateReceivedNumForm").fillData(result.data);
                    //打开修改模态框
                    js.modal.open('modal-updateReceivedNum');
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /**
     * 修改
     */
    function openUpdateModal(trackNumber) {
        js.post({
            url: ctx + "buy/procurementPlan/getBillTypeList",
            success: function (result) {
                //如果文件存在
                if (result.type === "SUCCESS") {
                    let list = result.data;
                    let selectBillType = $("#billType");
                    selectBillType.empty();
                    selectBillType.append('<option value="" selected>  ---请选择---  </option>');
                    for (let i = 0; i < list.length; i++) {
                        selectBillType.append('<option value="' + list[i].name + '">' + list[i].name + '</option>');
                    }
                    js.post({
                        url: ctx + "buy/procurementPlan/getBPreOrderPlanAllInfoByTrackNumber",
                        data: {trackNumber: trackNumber},
                        success: function (result) {
                            //如果文件存在
                            if (result.type === "SUCCESS") {
                                result.data.purchNum = result.data.num;
                                $("#updateForm").fillData(result.data);
                                $("#billType").val(result.data.billType).trigger("change");
                                //打开修改模态框
                                js.modal.open('modal-update');
                            } else {
                                js.modal.warning(result.msg);
                            }
                        }
                    });
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
</script>
</body>
</html>